package test.com.sms.selenium.singlepoint.util;

import org.openqa.selenium.By;

import test.com.sms.selenium.framework.SeleniumPageUtil;
import test.com.sms.selenium.util.SeleniumUtil;

public class SpIncidentEditAttachmentTabPageUtil extends
		SeleniumPageUtil {

	public final static By IEA_LINK_NEW = By.id("Attachments_btnNew");
	public final static By IEA_SPAN_TITLE = By.xpath("//*[@id='pnlPage']/table/tbody/tr/td/table[3]/tbody/tr/td[2]");
	public final static By IEA_TD_FIELD = By.xpath("//*[@id='Attachments_FileUploadPanel']/table/tbody/tr[1]/td[1]");
	public final static By IEA_INPUT_FILE = By.id("Attachments_FileUpload");
	public final static By IEA_TD_TITLE = By.xpath("//*[@id='Attachments_FileUploadPanel']/table/tbody/tr[2]/td[1]");
	public final static By IEA_INPUT_TITLE = By.id("Attachments_FileUploadTitle");
	public final static By IEA_TD_KEYWORD = By.xpath("//*[@id='Attachments_FileUploadPanel']/table/tbody/tr[3]/td[1]");
	public final static By IEA_INPUT_KEYWORD = By.id("Attachments_FileUploadKeywords");
	public final static By IEA_TD_COMMENT = By.xpath("//*[@id='Attachments_FileUploadPanel']/table/tbody/tr[4]/td[1]");
	public final static By IEA_INPUT_COMMENT = By.id("Attachments_FileUploadComment");
	public final static By IEA_TD_VISIBILITY = By.xpath("//*[@id='Attachments_FileUploadPanel']/table/tbody/tr[5]/td[1]");
	public final static By IEA_RADIO_PUBLIC = By.id("Attachments_btnVisibility_0");
	public final static By IEA_LABEL_PUBLIC = By.xpath("//*[@id='Attachments_btnVisibility']/tbody/tr[1]/td/label");
	public final static By IEA_RADIO_PRIVATE = By.id("Attachments_btnVisibility_1");
	public final static By IEA_LABEL_PRIVATE = By.xpath("//*[@id='Attachments_btnVisibility']/tbody/tr[2]/td/label");
	public final static By IEA_BTN_UPLOAD = By.id("Attachments_fileUploadSubmit"); 
	public final static By IEA_BTN_CANCEL = By.id("Attachments_fileUploadCancel"); 
	
	//field table result
	public final static By IEA_TABLE_RESULT = By.id("tblResults");
	public final static By IEA_TR_RESULT_LINES = By.xpath("//*[@id='tblResults']/tbody/tr");
	public final static By IEA_TD_DELETE = By.xpath("//*[@id='tblResults']/tbody/tr/td[1]");
	public final static By IEA_TD_FIELD_NAME = By.xpath("//*[@id='tblResults']/tbody/tr/td[2]");
	public final static By IEA_TD_FIELD_TITLE = By.xpath("//*[@id='tblResults']/tbody/tr/td[3]");
	public final static By IEA_TD_FIELD_TYPE = By.xpath("//*[@id='tblResults']/tbody/tr/td[4]");
	public final static By IEA_TD_FIELD_SIZE = By.xpath("//*[@id='tblResults']/tbody/tr/td[5]");
	public final static By IEA_TD_UPLOAD = By.xpath("//*[@id='tblResults']/tbody/tr/td[6]");
	public final static By IEA_TD_FIDLE_KEY = By.xpath("//*[@id='tblResults']/tbody/tr/td[7]");
	public final static By IEA_TD_FIELD_COMMENT = By.xpath("//*[@id='tblResults']/tbody/tr/td[8]");
	public static void enterAttachmentTab(String incidentId){
		// login into homepage
		SpSearchPageUtil.enter();
		// make sure search button and incident id input text show
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(SpIncidentEditPageUtil.IE_BUTTON_SEARCH)));
		SeleniumUtil.assertTrue(SeleniumUtil.isDisplayed(SeleniumUtil.getCachedElement(SpIncidentEditPageUtil.IE_MAIN_INPUT_INCIDENT_ID)));
		// click the incident id link to enter the edit page
		SpIncidentEditPageUtil.enterIncidentID(incidentId);
		//click Assets link to enter incident/Asset edit page
		SeleniumUtil.click(SeleniumUtil.getCachedElement(SpIncidentEditPageUtil.IE_LINK_TAB_ATTACHMENTS));
		waitForPageToLoad();
	}
	public static void waitForPageToLoad(){
		SeleniumUtil.selectDefaultContent();
		SeleniumUtil.waitOnElements(new By[]{
				IEA_LINK_NEW,IEA_INPUT_FILE,IEA_BTN_UPLOAD,IEA_TD_FIELD_COMMENT
		});
	}
}
